package top.auntie.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.auntie.bean.IdDto;
import top.auntie.bean.PageReq;
import top.auntie.bean.Result;
import top.auntie.model.Org;
import top.auntie.service.OrgService;

import java.sql.ResultSet;

@RestController
@RequestMapping("/org")
public class OrgController {

    @Autowired
    private OrgService orgService;

    @GetMapping("/query")
    public Result queryOrg(PageReq pageReq){
        return Result.success(orgService.queryOrg(pageReq));
    }

    @PostMapping("/save")
    public Result saveOrg(@RequestBody Org org){
        orgService.saveOrg(org);
        return Result.success();
    }

    @PostMapping("/del")
    public Result delOrg(@RequestBody IdDto idDto){
        orgService.deleteOrg(idDto.getId());
        return Result.success();
    }

    @GetMapping("/info")
    public Result getOrg(Integer id) {
        return Result.success(orgService.getOrgById(id));
    }

    @GetMapping("/select")
    public Result orgSelect() {
        return Result.success(orgService.getAllOrg());
    }

}
